package com.qc.ds.util;

import java.math.BigDecimal;

public class BigDecimalUtil {
	/**
	 * @author oenone
	 * @return BigDecimal
	 * @time 2017 下午6:06:44
	 * @desc 加法
	 */
	public static BigDecimal add(double v1, double v2) {
		BigDecimal b1 = new BigDecimal(Double.toString(v1));
		BigDecimal b2 = new BigDecimal(Double.toString(v2));
		return b1.add(b2);
	}

	/**
	 * @author oenone
	 * @return BigDecimal
	 * @time 2017 下午6:06:44
	 * @desc 减法
	 */
	public static BigDecimal sub(double v1, double v2) {
		BigDecimal b1 = new BigDecimal(Double.toString(v1));
		BigDecimal b2 = new BigDecimal(Double.toString(v2));
		return b1.subtract(b2);
	}

	/**
	 * @author oenone
	 * @return BigDecimal
	 * @time 2017 下午6:06:44
	 * @desc 乘法
	 */
	public static BigDecimal mul(double v1, double v2) {
		BigDecimal b1 = new BigDecimal(Double.toString(v1));
		BigDecimal b2 = new BigDecimal(Double.toString(v2));
		return b1.multiply(b2);
	}

	/**
	 * @author oenone
	 * @return BigDecimal
	 * @time 2017 下午6:06:44
	 * @desc 除法(保留两位小数，四舍五入)
	 */
	public static BigDecimal div(double v1, double v2) {
		BigDecimal b1 = new BigDecimal(Double.toString(v1));
		BigDecimal b2 = new BigDecimal(Double.toString(v2));
		return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP);// 保留两位小数，四舍五入
	}

}
